package ar.com.spsolutions.splilabrary.view.pages.book;

import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.validator.StringValidator;

import ar.com.spsolutions.splibrary.book.exceptions.ISBNException;
import ar.com.spsolutions.splibrary.utils.ISBNValidatorUtil;

public class ISBNValidatorBehavior extends StringValidator {

	private static final long serialVersionUID = 6540378729713687981L;

	@Override
	protected void onValidate(final IValidatable<String> validatable) {
		try {
			ISBNValidatorUtil.validate(validatable.getValue());
		} catch (final ISBNException e) {
			this.error(validatable);
		}
	}

	@Override
	protected String resourceKey() {
		return "ISBValidator.error";
	}
}
